package operation.modules.flashData.controller;

import operation.modules.flashData.dto.FlashDTO;
import operation.modules.flashData.entity.FlashDataEntity;
import operation.modules.flashData.service.FlashDataService;
import operation.modules.workReport.entity.WorkCustomEntity;
import operation.modules.workReport.service.WorkCustomService;
import operation.util.ReqResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* 客户 控制层
*/
@RestController
@RequestMapping("api/flashdata")
public class FlashDataController {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private FlashDataService flashDataService;
    /**
     * 查询所有父类
     */
    @RequestMapping("/query")
    public ReqResult queryByParentId(@RequestBody Map<String, Object> params) {
        logger.info("数据表 根据条件查询");
        List<FlashDataEntity> list = flashDataService.query(params);
        return ReqResult.ok().put("list", list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ReqResult save(@RequestBody FlashDataEntity flashDataEntity) {
        logger.info("数据表 保存信息");
        flashDataEntity.setParentId(flashDataEntity.getSelectedIds().get(flashDataEntity.getSelectedIds().size() - 1));
        flashDataService.save(flashDataEntity);
        return ReqResult.ok();
    }

    /**
     * 查询所有结构
     */
    @RequestMapping("/query-all")
    public ReqResult queryAll() {
        logger.info("数据表 查询所有结构");
        List<FlashDTO> flashDTOS = flashDataService.queryAll();
        return ReqResult.ok().put("list", flashDTOS);
    }

    /**
     * 根据id查询
     */
    @RequestMapping("/query-by-id")
    public ReqResult queryById(@RequestBody Map<String, Object> params) {
        logger.info("数据表 根据id查询");
        FlashDataEntity res = flashDataService.queryById(params);
        return ReqResult.ok().put("res", res);
    }
}